package org.xg.domain;

import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * 权限表
 * @author xg
 *
 */
@Entity
@Table(name = "SYS_AUTHORITY")
public class AuthorityVO extends IdEntity {//implements GrantedAuthority, Serializable

	private String authCode;
	private String authName;
	private Integer sortNum;
	private AuthorityVO parent;
	
	private Set<User2AuthorityVO> users2auth;	//用户、权限中间表
	private Set<Role2AuthorityVO> role2auth; 	//角色、权限中间表

	public AuthorityVO(){}
	
	/*
	public boolean equals(Object obj) {
	    if (obj instanceof String) {
	        return obj.equals(this.authCode);
	    }
	
	    if (obj instanceof GrantedAuthority) {
	        GrantedAuthority attr = (GrantedAuthority) obj;
	
	        return this.authCode.equals(attr.getAuthority());
	    }
	
	    return false;
	}
	public String getAuthority() {
	    return this.authCode;
	}
	
	public int hashCode() {
	    return this.authCode.hashCode();
	}

	public String toString() {
	    return this.authCode;
	}
	*/
	
	//----- getter and setter -----
	public String getAuthCode() {
		return authCode;
	}

	public void setAuthCode(String authCode) {
		this.authCode = authCode;
	}

	public String getAuthName() {
		return authName;
	}

	public void setAuthName(String authName) {
		this.authName = authName;
	}

	public Integer getSortNum() {
		return sortNum;
	}

	public void setSortNum(Integer sortNum) {
		this.sortNum = sortNum;
	}

	@ManyToOne
	@JoinColumn(name = "PARENT_ID")
	public AuthorityVO getParent() {
		return parent;
	}

	public void setParent(AuthorityVO parent) {
		this.parent = parent;
	}

	@OneToMany(mappedBy="auth")
	public Set<User2AuthorityVO> getUsers2auth() {
		return users2auth;
	}

	public void setUsers2auth(Set<User2AuthorityVO> users2auth) {
		this.users2auth = users2auth;
	}

	@OneToMany(mappedBy="auth")
	public Set<Role2AuthorityVO> getRole2auth() {
		return role2auth;
	}

	public void setRole2auth(Set<Role2AuthorityVO> role2auth) {
		this.role2auth = role2auth;
	}

	public AuthorityVO(String authCode) {
	    this.authCode = authCode;
	}
	

}
